//. Event-study Estimates by Armed Actor Type
	
	estimates clear
	
	set scheme s2color  

		* All Attacks
	
	loc dir "/Users/mateo/Desktop/"
	
	cd "/Users/mateo/Desktop/"
	
		use "/Users/mateo/Desktop/master_violence_landtitle_caracteristicas.dta", clear
		
		loc controls altura rainfall coca_0_1 presence_mines1560 num_encomiendas1560 royalroaddist distancia_mercado pct_minority85 conflictos_1901_1917 conflictos_1918_1931 Violencia_48_a_53 anucraids1971_78 pop95  spatlagguerrsum100_100_1995 ltotal_plots_rfmd_1960_85 totviolencia85
	  
		
		foreach x in 1995 {
		
			preserve
			
				keep if Año<=`x'
							
				collapse (mean)  spatlagguerrsum100_100, by(codmpio)
				
				ren (spatlagguerrsum100_100)=_`x'
				
				tempfile neighbor
				save `neighbor', replace
			
			
			restore
			
			merge m:1 codmpio using `neighbor'
			drop _m
		
		
		}
		
		** Controls X year
			loc controlsXyear
			loc x
			
			foreach control of loc controls {
			
				loc x c.`control'##c.Año
				
				loc controlsXyear `controlsXyear' `x' 

			}
			
	** Indigenous Land Placebo 
		
		*drop chyears title_adopted

		by codmpio (Año), sort: gen first_title_pl_2 = sum(reserve_land_title) == 1
		gen first_title_pl_year_2=Año if first_title_pl_2==1
		
		bys codmpio (first_title_pl_year_2): replace first_title_pl_year_2= first_title_pl_year_2[_n-1] if mi(first_title_pl_year_2) 
		
		gen chyears=Año - first_title_pl_year_2
		replace chyears=-10 if chyears<=-10
		replace chyears=10 if chyears>=10

		gen title_adopted=0 if first_title_pl_year_2 > Año
		replace title_adopted = 1 if first_title_pl_year_2<=Año
		replace title_adopted =. if mi(first_title_pl_year_2)		
	
	    
		foreach var of varlist sumattacks_public sumattacks_paramilitary sumattacks_guerrilla {
		
			preserve
			
				gen as_`var'=asinh(`var')	
				loc varlab: var lab `var'
				
				for any low med high: gen X=.
				qui xi : areg  as_`var'  `controlsXyear' Año##coddepto i.chyears, r cluster(codmpio) absorb(codmpio)
				for Y in num 2/10 11/20: replace med=_b[_Ichyears_Y] if _Ichyears_Y==1 
				for Y in num 2/10 11/20: replace low=_b[_Ichyears_Y]-1.64*_se[_Ichyears_Y] if _Ichyears_Y==1 		//Note:10% C.I.
				for Y in num 2/10 11/20: replace high=_b[_Ichyears_Y]+1.64*_se[_Ichyears_Y] if _Ichyears_Y==1 //Note:10% C.I.
				replace med=0 if chyears==0 
				replace high=0+1*(_se[_Ichyears_10]+_se[_Ichyears_11])/2 if chyears==0 
				replace low=0-1*(_se[_Ichyears_10]+_se[_Ichyears_11])/2 if chyears==0 
				for Z in var low med high: replace Z=Z-(_b[_Ichyears_2]+_b[_Ichyears_3]+_b[_Ichyears_4]+_b[_Ichyears_5]+_b[_Ichyears_6] + _b[_Ichyears_7] + _b[_Ichyears_8] + _b[_Ichyears_9] + _b[_Ichyears_10] +0)/10 
				for Z in var low med high: replace Z=0 if chyears==0 
				twoway (line high chyears, sort lpattern(dash) color(green)) (line low chyears, sort lpattern(dash) color(green)) (connected med chyears, color(black) sort), ytitle("Point Estimate") ylabel(-0.6 "-60%" -0.4 "-40%" -0.2 "-20%"  0 "0%"  .2 "20%" .4 "40%" .6 "60%" .8 "80%"   1 "100%" 1.2 "120%", angle(horizontal)) yline(0, lcolor(black)) xtitle(Years Since/Until First Land Title Assigned) xlabel(-10(2)10 -10 "<-10 yrs" 10 ">10 yrs") xline(0, lcolor(black)) /*title(`"{bf: `varlab'}"', size(vlarge))*/ legend(order(2 "Coefficient Estimates" 1 "10% C.I.") off) xsize(5) ysize(3.5) name(`var', replace) graphregion(color(white)) 
				graph export `"as_`var'_placebo_Indigenous.png"', replace
				
			restore
				
		}
			
		graph combine sumattacks_public sumattacks_paramilitary sumattacks_guerrilla , ///
		saving(`violence_phasein_placebo_Indigenous.png"', replace) ycommon cols(1)  graphregion(color(white))  altshrink
			
		graph export `"violence_phasein_placebo_Indegenous.png"', replace
		
